package utils

import (
	"encoding/json"
	"gitee.com/hufengjiu/go-zinx/ziface"
	"io/ioutil"
)

var GlobalConf *GlobalConfig

type GlobalConfig struct {
	TcpServer      ziface.IServer
	Host           string
	TcpPort        int
	Name           string
	Version        string
	MaxPacketSize  uint32
	MaxConn        int
	WorkersSize    uint32
	WorkerQueueLen uint32
	MaxMsgChanLen  uint32
}

func InitConfig(filename string) {
	if filename == "" {
		GlobalConf = &GlobalConfig{
			Name:           "zinxServer",
			Version:        "v0.3",
			TcpPort:        8999,
			Host:           "0.0.0.0",
			MaxConn:        12000,
			MaxPacketSize:  40960,
			WorkersSize:    10,
			WorkerQueueLen: 1024,
		}
	} else {
		data, err := ioutil.ReadFile(filename)
		if err != nil {
			panic(err)
		}

		err = json.Unmarshal(data, &GlobalConf)
		if err != nil {
			panic(err)
		}
	}

}
